package com.linpq.road.controller;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.linpq.system.mapper.SysDictTypeMapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.linpq.common.annotation.Log;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RdPavementMaterials;
import com.linpq.road.service.RdPavementMaterialsService;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.utils.poi.ExcelUtil;
import com.linpq.common.core.page.TableDataInfo;

/**
 * 路面材料Controller
 *
 * @author linpq
 * @date 2021-07-29
 */
@Controller
@RequestMapping("/road/pavement_materials")
public class RdPavementMaterialsController extends BaseController {
    private String prefix = "road/pavement_materials";

    @Autowired
    private RdPavementMaterialsService rdPavementMaterialsService;

    @RequiresPermissions("road:pavement_materials:view")
    @GetMapping()
    public String pavement_materials() {
        return prefix + "/pavement_materials";
    }


    @GetMapping("/form")
    public String form(Model map) {
        Map<String, List<String>> stringListMap = rdPavementMaterialsService.selectRdPavementMaterialsNameList();
        map.addAttribute("pavementMaterislas",stringListMap);
        return prefix + "/stake_form_pavement_materials";
    }
    /**
     * 查询路面材料列表
     */
    @RequiresPermissions("road:pavement_materials:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RdPavementMaterials rdPavementMaterials) {
        startPage();
        List<RdPavementMaterials> list = rdPavementMaterialsService.selectRdPavementMaterialsList(rdPavementMaterials);
        return getDataTable(list);
    }

    /**
     * 导出路面材料列表
     */
    @RequiresPermissions("road:pavement_materials:export")
    @Log(title = "路面材料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RdPavementMaterials rdPavementMaterials) {
        List<RdPavementMaterials> list = rdPavementMaterialsService.selectRdPavementMaterialsList(rdPavementMaterials);
        ExcelUtil<RdPavementMaterials> util = new ExcelUtil<RdPavementMaterials>(RdPavementMaterials. class);
        return util.exportExcel(list, "pavement_materials");
    }

    /**
     * 新增路面材料
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存路面材料
     */
    @RequiresPermissions("road:pavement_materials:add")
    @Log(title = "路面材料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RdPavementMaterials rdPavementMaterials) {
        return toAjax(rdPavementMaterialsService.insertRdPavementMaterials(rdPavementMaterials));
    }

    /**
     * 修改路面材料
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        RdPavementMaterials rdPavementMaterials =rdPavementMaterialsService.selectRdPavementMaterialsById(id);
        mmap.put("rdPavementMaterials", rdPavementMaterials);
        return prefix + "/edit";
    }

    /**
     * 修改保存路面材料
     */
    @RequiresPermissions("road:pavement_materials:edit")
    @Log(title = "路面材料", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RdPavementMaterials rdPavementMaterials) {
        return toAjax(rdPavementMaterialsService.updateRdPavementMaterials(rdPavementMaterials));
    }

    /**
     * 删除路面材料
     */
    @RequiresPermissions("road:pavement_materials:remove")
    @Log(title = "路面材料", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(rdPavementMaterialsService.deleteRdPavementMaterialsByIds(ids));
    }
    @RequestMapping(value = "/saveRoadPavementMaterialsInit",method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult saveRoadPavementMaterialsInit(@RequestParam Map data) throws SQLException {
        AjaxResult ajaxResult = rdPavementMaterialsService.insertPavementMaterialsByRoadSectionName(data);
        return ajaxResult;
    }
}
